#coding=utf-8
'''
Using cxfreeze to create a lonote.exe file.

    Dependency: Windows platform, Python >= 3.2, cx_freeze

# How To Use:

    py THISFILE build_exe

The .exe directory will be placed in "build_exe" folder.
'''

import os
import sys
import platform

from cx_Freeze import setup, Executable


def execDir():
    '''執行檔所在資料夾'''
    return os.path.abspath(os.path.dirname(sys.argv[0]))
    # return os.path.dirname(os.path.realpath(__file__))

# source pack library change
src_lib_dir = os.path.join(execDir(), 'lonotelib')
sys.path[0] = src_lib_dir


import lonote.info

# 測試與收集資料
bits, linkage = platform.architecture()
if platform.system() == 'Windows':
    if bits.startswith('32'):
        bit = 'win32'
    elif bits.startswith('64'):
        bit = 'win64'
else:
    print('Only work on windows platform. Cancel.')
    sys.exit()

build_dir = "build_exe"
exe_dir = "lonote-{ver}-{bit}".format(ver = lonote.info.version, bit = bit)
build_exe_dir = os.path.join(build_dir, exe_dir)

build_exe_options = {
    "build_exe": build_exe_dir,
    "packages": ["os", 'urllib.request', 'decimal', 'lonote.translate'],
    "include_files": ['server', 'config', 'doc/Win', 'locale'],
    "icon": os.path.join("desktop", "lonote.ico"),
    "include_msvcr": True}


setup(name='lonote',
      version = lonote.info.version,
      description = lonote.info.desc_long,
      author = lonote.info.designer,
      author_email = lonote.info.designer_mail,
      url = lonote.info.homepage,
      download_url = lonote.info.download_url,
      classifiers=[
        'Environment :: Web Environment',
        'Intended Audience :: End Users/Desktop',
        'License :: OSI Approved :: Apache Software License',
        'Operating System :: Microsoft :: Windows',
        'Operating System :: POSIX :: Linux',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: JavaScript',
        'Topic :: Internet :: WWW/HTTP :: WSGI',
        'Topic :: Text Editors'
        ],
      scripts=['lonote.py'],
      py_modules=[ 'diff_match_patch',
          'bottle',
          'lonote.translate'],
      package_dir = {'': 'lonotelib'},
      packages=['lonote',
          'civa',
          'whoosh',
          'whoosh.codec',
          'whoosh.filedb',
          'whoosh.lang',
          'whoosh.matching',
          'whoosh.qparser',
          'whoosh.query',
          'whoosh.support'],
      options = {"build_exe": build_exe_options},
      executables = [Executable("lonote.py", base='Win32GUI')]
      )

